﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Media;

namespace H_GAME
{
    public class Cls_Bio
    {
        #region 属性变量
        public int sp_width;
        public int old_x;

        public SoundPlayer player = new SoundPlayer(); //音效

        public int hardindex;
        public bool isfinished = true; //是否完成动作
        public string sourpath;//Application.StartupPath + "\\Pic\\Hammer1

        public int CurrentTargetIndex = 0;
        public string CurrentTargetName = "";
        public Bitmap liveFrameImg; //生命值显示栏
        public Bitmap liveImg; //生命值显示图片
        public Bitmap liveImgBak; //生命值显示图片背景
        public int EfficDelay = 0; //特效延迟值

        /// <summary>
        /// 主键
        /// </summary>
        private int id;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// 是否是玩家
        /// </summary>
        private bool isplayer;
        public bool Isplayer
        {
            get { return isplayer; }
            set { isplayer = value; }
        }

        /// <summary>
        /// 人物姓名
        /// </summary>
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// 目标集合区域
        /// </summary>
        private ArrayList targetrecs;
        public ArrayList Targetrecs
        {
            get { return targetrecs; }
            set { targetrecs = value; }
        }

        /// <summary>
        /// 是否胜利
        /// </summary>
        private bool isvictory;
        public bool Isvictory
        {
            get { return isvictory; }
            set { isvictory = value; }
        }

        public bool Isfinished
        {
            get { return isfinished; }
            set { isfinished = value; }
        }

        /// <summary>
        /// 是否被击中
        /// </summary>
        private bool isbyhit;
        public bool Isbyhit
        {
            get { return isbyhit; }
            set { isbyhit = value; }
        }

        /// <summary>
        /// 是否防御
        /// </summary>
        private bool isbydef;
        public bool Isbydef
        {
            get { return isbydef; }
            set { isbydef = value; }
        }


        /// <summary>
        /// 攻击力
        /// </summary>
        private int destroyedval;
        public int Destroyedval
        {
            get { return destroyedval; }
            set { destroyedval = value; }
        }

        /// <summary>
        /// 默认攻击力
        /// </summary>
        private int defaultdestroyedval;
        public int Defaultdestroyedval
        {
            get { return defaultdestroyedval; }
            set { defaultdestroyedval = value; }
        }


        /// <summary>
        /// 攻击区域
        /// </summary>
        private Rectangle actrec;
        public Rectangle Actrec
        {
            get { return actrec; }
            set { actrec = value; }
        }

        /// <summary>
        /// 防守区域
        /// </summary>
        private Rectangle defrec;
        public Rectangle Defrec
        {
            get { return defrec; }
            set{defrec= value;}
        }

        /// <summary>
        /// 攻击有效区域
        /// </summary>
        private Rectangle bodyrec;
        public Rectangle Bodyrec
        {
            get { return bodyrec; }
            set { bodyrec = value; }
        }

      


       

        /// <summary>
        /// 是否自动操作
        /// </summary>
        private bool autoflag;
        public bool Autoflag
        {
            get { return autoflag; }
            set { autoflag = value; }
        }



        /// <summary>
        /// 队伍
        /// </summary>
        private int team;
        public int Team
        {
            get { return team; }
            set { team = value; }
        }


        /// <summary>
        /// 底坐标
        /// </summary>
        private int p_y;
        public int P_y
        {
            get { return p_y; }
            set { p_y = value; }
        }

        /// <summary>
        /// 图片地址
        /// </summary>
        private string _imgpath;
        public string Imgpath
        {
            get { return _imgpath; }
            set { _imgpath = value; }
        }

        /// <summary>
        /// 图片显示
        /// </summary>
        private Bitmap _img;
        public Bitmap Img
        {
            get { return _img; }
            set { _img = value; }
        }

        /// <summary>
        /// 头像图片显示
        /// </summary>
        private Bitmap _headimg;
        public Bitmap Headimg
        {
            get { return _headimg; }
            set { _headimg = value; }
        }

        /// <summary>
        /// 速度
        /// </summary>
        private int speed;
        public int Speed
        {
            get { return speed; }
            set { speed = value; }
        }

        /// <summary>
        /// 跳跃上升高度
        /// </summary>
        private int maxjump;
        public int Maxjump
        {
            get { return maxjump; }
            set { maxjump = value; }
        }

        /// <summary>
        /// 跳跃上升高度
        /// </summary>
        private int maxdttop;
        public int Maxdttop
        {
            get { return maxdttop; }
            set { maxdttop = value; }
        }


        /// <summary>
        /// 跳跃当前高度
        /// </summary>
        private int jumpheight;
        public int Jumpheight
        {
            get { return jumpheight; }
            set { jumpheight = value; }
        }



        /// <summary>
        /// 下落速度
        /// </summary>
        private int downspeed;
        public int Downspeed
        {
            get { return downspeed; }
            set { downspeed = value; }
        }

        public int jumpdowflag = 0; //下落标志

        public int delay = 0; //下落延迟参数

        /// <summary>
        /// X坐标
        /// </summary>
        private int x;
        public int X
        {
            get { return x; }
            set { x = value; }
        }

        /// <summary>
        /// Y坐标
        /// </summary>
        private int y;
        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        /// <summary>
        /// 角色类型
        /// </summary>
        private int _kind;
        public int Kind
        {
            get { return _kind; }
            set { _kind = value; }
        }

        /// <summary>
        /// 生命值
        /// </summary>
        private int live;
        public int Live
        {
            get { return live; }
            set { live = value; }
        }


        /// <summary>
        /// 生命槽长度
        /// </summary>
        private int livebarwidth;
        public int Livebarwidth
        {
            get { return livebarwidth; }
            set { livebarwidth = value; }
        }

        /// <summary>
        /// 图片类型
        /// </summary>
        private string imgtype;
        public string Imgtype
        {
            get { return imgtype; }
            set { imgtype = value; }
        }

        /// <summary>
        /// 图片索引
        /// </summary>
        private int imgindex;
        public int Imgindex
        {
            get { return imgindex; }
            set { imgindex = value; }
        }

        /// <summary>
        /// 方向 R 右 L 左
        /// </summary>
        private string func;
        public string Func
        {
            get { return func; }
            set { func = value; }
        }
        #endregion

        #region 行为动作

         

        /// <summary>
        /// 获取中心点
        /// </summary>
        /// <param name="rec"></param>
        /// <returns></returns>
        public Point GetMiddleP(Rectangle rec)
        {
            int m_x = 0;
            int m_y = 0;
            m_x = rec.X + rec.Width / 2;
            m_y = rec.Y + rec.Height / 2;
            Point p = new Point(m_x, m_y);
            return p;
        }

        /// <summary>
        /// 自动操作 电脑智能
        /// </summary>
        public void Auto()
        {
            if (Live > 0 && !Isvictory)
            {
                if (Autoflag)
                {
                    if (isfinished && !Isbyhit)
                    {
                        #region 无目的自动
                        //Random tn = new Random();
                        //int type = tn.Next(0, 400);
                        //if (type > 20 && type < 30)
                        //{
                        //    if (X <= 0)
                        //    {
                        //        Func = "R";
                        //    }
                        //    else if (X <= X - Img.Width)
                        //    {
                        //        Func = "L";
                        //    }
                        //    Imgtype = "Z";
                        //}
                        //else if (type > 41 && type < 50)
                        //{
                        //    Imgtype = "S";
                        //}

                        //else if (type > 61 && type < 65)
                        //{
                        //    if (Func == "L")
                        //    {
                        //        Func = "R";
                        //    }
                        //    else
                        //    {
                        //        Func = "L";
                        //    }
                        //}
                        //else if (type > 100 && type < 102)
                        //{
                        //    Imgtype = "V";
                        //}
                        //else if (type > 200 && type < 210)
                        //{
                        //    Imgtype = "A1";
                        //}
                        //else if (type > 250 && type < 255)
                        //{
                        //    Imgtype = "A2";
                        //}
                        //else if (type > 290 && type < 295)
                        //{
                        //    Imgtype = "A3";
                        //}
                        //else if (type > 240 && type < 245)
                        //{
                        //    Imgtype = "DefD";
                        //}
                        //else if (type > 270 && type < 275)
                        //{
                        //    Imgtype = "DefS";
                        //}
                        //else if (type > 281 && type < 285)
                        //{
                        //    Imgtype = "JP";
                        //}
                        #endregion

                        #region 搜索目标进攻
                        if (Targetrecs != null)
                        {
                            int lindex = 0;
                            int lspance = 0;
                            string tempfunc = Func; //方向
                            Rectangle currentRec = new Rectangle(X, Y, Img.Width, Img.Height);
                            Point CunrrentPoint = GetMiddleP(currentRec);

                            for (int i = 0; i < Targetrecs.Count; i++)
                            {
                                //就近原则寻找目标
                                Cls_Bio tempHammer = (Cls_Bio)Targetrecs[i];
                                if (tempHammer.live > 0)
                                {
                                    Rectangle temptarget = new Rectangle(tempHammer.X, tempHammer.Y, tempHammer.Img.Width, tempHammer.Img.Height);
                                    Point CunrrentTargetPoint = GetMiddleP(temptarget);
                                    int currentspance = 0;
                                    if (CunrrentPoint.X > CunrrentTargetPoint.X)
                                    {
                                        currentspance = CunrrentPoint.X - CunrrentTargetPoint.X;
                                        tempfunc = "L";
                                    }
                                    else
                                    {
                                        currentspance = temptarget.X - CunrrentTargetPoint.X;
                                        tempfunc = "R";
                                    }

                                    if (lspance == 0)
                                    {
                                        lspance = currentspance;
                                        lindex = i;
                                    }
                                    else
                                    {
                                        if (currentspance < lspance)
                                        {
                                            //获取距离更近的
                                            lspance = currentspance;
                                            lindex = i;
                                            CurrentTargetIndex = tempHammer.Id;
                                        }
                                    }
                                }
                            }

                            if (Targetrecs.Count > 0)
                            {
                                Cls_Bio tempHammer = (Cls_Bio)Targetrecs[lindex];
                                Rectangle target = new Rectangle(tempHammer.X, tempHammer.Y, tempHammer.Img.Width, tempHammer.Img.Height);//取得定位的目标
                                if (tempHammer.live > 0)
                                {
                                    //行为设定
                                    if (tempfunc == "L")
                                    {
                                        Func = "L";

                                    }
                                    else
                                    {
                                        Func = "R";
                                    }

                                    if (lspance > 300 || lspance<-300)
                                    {
                                        Random temprn1 = new Random();
                                        int tval = temprn1.Next(0, 10);
                                        if (tval == 2 || tval == 5)
                                            Imgtype = "JP";
                                        else
                                            Imgtype = "Z";
                                    }
                                    else
                                    {
                                        Random temprn2 = new Random();
                                        int type = temprn2.Next(0, 1000 / hardindex);

                                        if (type > 0 && type < 10)
                                        {
                                            Imgtype = "S";
                                            Imgindex = 0;
                                        }
                                        else if (type > 10 && type < 20)
                                        {
                                            Imgtype = "A1";
                                            Imgindex = 0;

                                        }
                                        else if (type > 20 && type < 30)
                                        {
                                            Imgtype = "A2";
                                            Imgindex = 0;

                                        }
                                        else if (type > 30 && type < 40)
                                        {
                                            Imgtype = "A3";
                                            Imgindex = 0;
                                        }
                                        else if (type > 40 && type < 50)
                                        {
                                            Imgtype = "A4";
                                            Imgindex = 0;
                                        }                                    
                                        else if (type > 50 && type < 60)
                                        {
                                            Isbydef = false;
                                            Imgtype = "DefD";
                                            Imgindex = 0;
                                        }
                                        else if (type > 60 && type < 90)
                                        {
                                            Isbydef = false;
                                            Imgtype = "DefS";
                                            Imgindex = 0;
                                        }
                                        else if (type > 90 && type < 100)
                                        {
                                            Imgtype = "Z";
                                            Imgindex = 0;
                                        }
                                        else if (type > 100 && type < 110)
                                        {
                                            Imgtype = "A5";
                                            Imgindex = 0;
                                        }
                                        else if (type > 110 && type < 120)
                                        {
                                            Imgtype = "A1";
                                            Imgindex = 0;
                                        }
                                        else 
                                        {
                                            Imgtype = "S";
                                            Imgindex = 0;
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
            else
            {
                if (Live <= 0)
                {
                    Imgtype = "DT1";
                    delay = 0;
                }
                if (Isvictory)
                {
                    if(Live>0)
                       Imgtype = "V";
                }
            }
        }
        #endregion

    }
}
